package com.zyit.web;

import com.zyit.DataObject.T_user;
import com.zyit.dao.UserDao;
import com.zyit.util.SendEmail;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/emailLongin")
public class EmailServlet extends HttpServlet {
private UserDao userDao = new UserDao();
private SendEmail sendEmail = new SendEmail();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String email = req.getParameter("email");
        System.out.println(email);
        T_user tUser = userDao.emailByUser(email);
        System.out.println(tUser);
        String userName = req.getParameter("userName");
        T_user tUser1 = userDao.nameByUser(userName);
        System.out.println(tUser1);

        if(tUser != null && tUser1 != null){
        if(tUser.getEmail().equals(tUser1.getEmail())){

                String s = sendEmail.SendEmailGo(email);
                System.out.println(s);

            resp.getWriter().write("{\"status\": 1, \"data\": \"" + s + "\", \"account\": \"" + tUser.getAccount() + "\", \"password\": \"" + tUser.getPassword() + "\"}");

            }else {
            resp.getWriter().write("{\"status\": 3}");
        }
        }else {
            resp.getWriter().write("{\"status\": 2}");
        }

    }
}
